import React, { PureComponent } from "react";
import { connect } from "react-redux";
import Home from "components/My/Home";
import {Login} from 'actions/common'
import {isOverflow} from 'app/utils'
import { callApi } from "app/utils";
@connect(
  state => ({
    common: state.common,
    login: state.login
  }),
  {
    Login
  }
)
export default class extends PureComponent {
  constructor(props) {
    super(props);
    this.state = {
      overview:{}
    };
    
  }

  componentDidMount() {
    let {Login} = this.props
    
    if(localStorage.getItem("userData")!=undefined&&localStorage.getItem('userData')!="undefined"&&localStorage.getItem("userData")!=null){
      let token = JSON.parse(localStorage.getItem("userData")).token;
      callApi("/home/overview", { token: token }, "POST").then(data => {
        this.setState({
          overview:data
        })
      })
    }
   
    
    if(this.props.common.isLogin==true){
      isOverflow(false)
    }else{
      isOverflow(true)
    }
  }
  componentWillReceiveProps(nextProps) {
   
   // console.log(nextProps,'nextProps')
  }
  componentWillUnmount() {
    isOverflow(false)
  }
  
  render() {
    let {isLogin} = this.props.login
    let {overview} = this.state
    return (
      <div>
        <Home
        props={this.props}
        isLogin={isLogin}
        overview={overview}
        />
      </div>
    );
  }
}
